/*
 * Copyright (c) 2010, 2012 Luan Nguyen Thanh. All rights reserved.
 * 
 * This code is written by Luan Nguyen Thanh, with any partners involved.
 * The unauthorized use of this code should not be permitted!
 */
package MyIM.client.view.lnf;

import de.javasoft.plaf.synthetica.SyntheticaLookAndFeel;
import de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel;
import de.javasoft.plaf.synthetica.SyntheticaWhiteVisionLookAndFeel;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.text.ParseException;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Luan Nguyen Thanh <tklarryonline@gmail.com>
 */
public class MetroStyle {

    public static final Color BLUE = new Color(0x1b, 0xa1, 0xe2),
            RED = new Color(0xe5, 0x14, 0x00),
            GREEN = new Color(0x33, 0x99, 0x33),
            MARINE = new Color(0x03, 0x48, 0x88),
            LIGHTER_MARINE = new Color(0x29, 0x7A, 0xCC),
            TEAL_ORANGE = new Color(0xd5, 0x4d, 0x34);
    public static final Font BUTTON_FONT = SegoeFont.getSegoeUIFont("normal",
            15.8f);
    public static final Font SMALL_BUTTON_FONT = SegoeFont.getSegoeUIFont(
            "normal", 13.4f);
    public static final Font FORM_TITLE = SegoeFont.getSegoeUIFont("light", 36f);
    public static final Font FORM_HEADER = SegoeFont.getSegoeUIFont("normal",
            16f);

    public static void setLookAndFeel(Style style) {
        try {
            // Customizes the default Java L&F
            UIManager.put("MenuItem.selectionForeground", Color.WHITE);

            // Customizes the Synthetica L&F
            UIManager.put("Synthetica.window.arcW", 0);
            UIManager.put("Synthetica.window.arcH", 0);
            UIManager.put("Synthetica.rootPane.titlePane.iconifyButton.gap", 10);
            UIManager.put("Synthetica.rootPane.titlePane.toggleButton.gap", 10);
            UIManager.put("Synthetica.rootPane.titlePane.title.visible", false);
            UIManager.put("Synthetica.rootPane.titlePane.iconifyButton.insets",
                    new Insets(10, 0, 3, 0));
            UIManager.put("Synthetica.rootPane.titlePane.toggleButton.insets",
                    new Insets(10, 0, 3, 0));
            UIManager.put("Synthetica.rootPane.titlePane.closeButton.insets",
                    new Insets(10, 0, 3, 5));
            UIManager.put("Synthetica.rootPane.titlePane.menuBar.insets",
                    new Insets(10, 3, 3, 3));

            setLnF(style);

            // Sets custom font
            Font font = SegoeFont.getSegoeUIFont("normal");
            SyntheticaLookAndFeel.setFont(font);

            // Sets license for Synthetica pack
            String[] syntheticaLicense = {
                "Licensee=Nguyen Thanh Luan",
                "LicenseRegistrationNumber=NCNL120529",
                "Product=Synthetica",
                "LicenseType=Non Commercial",
                "ExpireDate=--.--.----",
                "MaxVersion=2.999.999"
            };
            UIManager.put("Synthetica.license.info", syntheticaLicense);
            UIManager.put("Synthetica.license.key",
                    "3328F49F-31D2DE58-63F25088-5D69B566-1039A8FD");

            // Sets license for Synthetica Addons pack
            String[] syntheticaAddonsLicense = {
                "Licensee=Nguyen Thanh Luan",
                "LicenseRegistrationNumber=NCNL120529",
                "Product=SyntheticaAddons",
                "LicenseType=Non Commercial",
                "ExpireDate=--.--.----",
                "MaxVersion=1.999.999"};
            UIManager.put("SyntheticaAddons.license.info",
                    syntheticaAddonsLicense);
            UIManager.put("SyntheticaAddons.license.key",
                    "8BF822DF-DCC143A8-BB6B46BF-DE468F33-35AF01FE");

        } catch (ParseException | UnsupportedLookAndFeelException ex) {
            // Sets system looks and feel. If there's exception, leave the L&F
            // be Java Default (Metal L&F).
            try {
                UIManager.setLookAndFeel(
                        UIManager.getSystemLookAndFeelClassName());
            } catch (UnsupportedLookAndFeelException |
                    ClassNotFoundException |
                    InstantiationException |
                    IllegalAccessException e) {
            }
        }
    }

    private static void setLnF(Style style) throws ParseException,
            UnsupportedLookAndFeelException {
        switch (style) {
            case LIGHT:
                UIManager.setLookAndFeel(new SyntheticaWhiteVisionLookAndFeel());
                break;
            case DARK:
//                UIManager.setLookAndFeel(new );
//                break;
            default:
                UIManager.setLookAndFeel(new SyntheticaStandardLookAndFeel());
                break;
        }
    }
}
